<!--  -->
<template>
  <div class=''>
    <el-form ref="formInline" :inline="true" size="small" :model="flagCusMolde" class="demo-form-inline">
      <el-form-item label="关键字搜索" prop="kw">
        <el-input v-model="flagCusMolde.kw" placeholder="关键字"></el-input>
      </el-form-item>
      <el-form-item label="数据来源" prop="clientId">
        <el-select v-model="flagCusMolde.clientId" placeholder="请选择状态">
          <el-option
          v-for="(item,index) in mesFromArr"
          :key="index"
          :label="item.tName"
          :value="item.tId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="时间范围">
        <el-date-picker
          v-model="flagCusMolde.value_flag"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          @click="getResource"
          class="queryButton"
          icon="el-icon-search">查询</el-button>
        <el-button
          class="resetButton"
          @click="resetQuery('formInline')"
          icon="el-icon-refresh">重置</el-button>
      </el-form-item>
    </el-form>
    <el-form>
      <!-- <el-button
        type="primary"
        plain
        class="queryButton"
        @click="addmyCusBtn"
        icon="el-icon-plus">新增</el-button> -->
      <el-button
        type="warning"
        @click="deleteBtnAll"
        icon="el-icon-delete"
        class="queryButton"
        v-permissions="'customers:delete'"
        plain
        style="margin-left: 5px;">批量删除客户</el-button>
      <el-button
        type="primary"
        @click="salvageFun"
        class="queryButton"
        v-permissions="'customers:salvage'"
        plain
        style="margin-left: 5px;">捞取</el-button>
      <el-button
        type="primary"
        class="queryButton"
        v-permissions="'customers:shareCus'"
        @click="shareFun"
        plain>分配</el-button>
    </el-form>
    <!-- 新增我的客户弹框 -->
    <el-dialog
      title="新增我的客户"
      :visible.sync="isShowaddMyCus"
      @close="addPopClose('roleForm')"
      :close-on-press-escape="true"
      :close-on-click-modal="false"
      width="25%">
      <el-form ref="roleForm" size="small" :model="myCusFromAdd" :rules="addMyCusRule" label-width="80px">
        <el-form-item label="客户名称" prop="cusName">
          <el-input v-model="myCusFromAdd.cusName"></el-input>
        </el-form-item>
        <el-form-item label="客户手机号" prop="phone">
          <el-input v-model="myCusFromAdd.phone"></el-input>
        </el-form-item>
        <el-form-item label="借款额度" prop="quota">
          <el-input v-model="myCusFromAdd.quota"></el-input>
        </el-form-item>
        <el-form-item label="客户星级" prop="level">
            <el-select v-model="myCusFromAdd.level" placeholder="请选择星级">
              <el-option label="1" value="1"></el-option>
              <el-option label="2" value="2"></el-option>
              <el-option label="3" value="3"></el-option>
              <el-option label="4" value="4"></el-option>
              <el-option label="5" value="5"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="客户状态" prop="status">
          <el-select v-model="myCusFromAdd.status" placeholder="请选择">
            <el-option
            v-for="(item,index) in flagStatusArr"
            :key="index"
            :label="item.name"
            :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="myCusFromAdd.remarks"></el-input>
        </el-form-item>
      </el-form>
      <div style="width: 100%; text-align: center;">
        <el-button 
          type="primary"
          plain
          @click="submitMycus"
          class="queryButton">保存</el-button>
        <el-button
          plain
          class="resetButton"
          @click="addPopClose('roleForm')">关闭</el-button>
      </div>
    </el-dialog>
    <!-- 详情我的客户弹框 -->
    <el-dialog
      title="客户详情"
      :visible.sync="showFlagDetailDia"
      :close-on-click-modal="false"
      :show-close="false"
      :close-on-press-escape="false"
      @click="closeDia"
      width="40%">
      <el-form ref="basicForm"
        :inline="false"
        size="small"
        class="demo-form-inline"
        :model="flagDetailObj"
        :rules="flagRule"
        label-position="left"
        label-width="220px">
        <div class="filter-container">
          <el-form-item label="客户名称" prop="name">
            <el-input v-model="flagDetailObj.name"></el-input>
          </el-form-item>
          <el-form-item label="客户电话" prop="phone">
            <el-input v-model="flagDetailObj.phone"></el-input>
          </el-form-item>
          <el-form-item label="备注">
            <el-input type="textarea" v-model="flagDetailObj.remarks"></el-input>
          </el-form-item>
          <el-form-item label="客户来源">
            <span>{{ flagDetailObj.clientName === null ? '-' : flagDetailObj.clientName }}</span>
          </el-form-item>
          <el-form-item label="公海名称" prop="seasId">
            {{ flagDetailObj.seasName }}
          </el-form-item>
          <el-form-item label="跟进人">
            <span>{{ flagDetailObj.followUpUser }}</span>
          </el-form-item>
          <el-form-item label="是否为重要客户">
            <span>{{ flagDetailObj.isFlag === 1 ? '是' : '否' }}</span>
          </el-form-item>
          <el-form-item label="客户状态" prop="statusID">
            <el-select v-model="flagDetailObj.status" placeholder="请选择客户状态">
                <el-option
                v-for="(item,index) in flagStatusArr"
                :key="index"
                :label="item.name"
                :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="星级">
            <el-select v-model="flagDetailObj.level" placeholder="请选择星级">
              <el-option label="1" value="1"></el-option>
              <el-option label="2" value="2"></el-option>
              <el-option label="3" value="3"></el-option>
              <el-option label="4" value="4"></el-option>
              <el-option label="5" value="5"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="创建时间">
            <span>{{ flagDetailObj.createTime === null ? '-' : timestampToDate(flagDetailObj.createTime) }}</span>
          </el-form-item>
          <el-form-item label="最新掉入公海时间">
            <span>{{ flagDetailObj.newDropTime === null ? '-' : timestampToDate(flagDetailObj.newDropTime) }}</span>
          </el-form-item>
          <el-form-item label="最新分配时间">
            <span>{{ flagDetailObj.newShareTime === null ? '-' : timestampToDate(flagDetailObj.newShareTime) }}</span>
          </el-form-item>
          <el-form-item label="最新跟进时间">
            <span>{{ flagDetailObj.newTime === null ? '-' : timestampToDate(flagDetailObj.newTime) }}</span>
          </el-form-item>
          <el-form-item label="更新时间">
            <span>{{ flagDetailObj.updateTime === null ? '-' : timestampToDate(flagDetailObj.updateTime) }}</span>
          </el-form-item>
          <el-form-item label="最新跟进记录" prop="newRecord">
            <span>{{ flagDetailObj.newRecord }}</span>
          </el-form-item>
          <el-form-item label="新增更进记录" prop="followUpRecord">
            <el-input v-model="flagDetailObj.followUpRecord"></el-input>
          </el-form-item>
          <el-form-item label="贷款额度" prop="quota">
            <el-input v-model="flagDetailObj.quota"></el-input>
          </el-form-item>
          <el-form-item label="查看跟进记录" prop="quota">
            <el-button
              type="primary"
              class="submitButton"
              @click="viewRecords(flagDetailObj.id)">点击查看</el-button>
          </el-form-item>
        </div>
      </el-form>
      <el-form class="buttons">
        <el-button
          type="primary"
          class="submitButton"
          @click="addConfigUserRole">保存</el-button>
        <el-button
          class="resetButton"
          @click="closeDia">关闭</el-button>
      </el-form>
    </el-dialog>
    <!-- 跟进记录 -->
    <el-dialog
      title="跟进记录"
      :visible.sync="isShowRecords"
      @close="isShowRecords = false"
      :close-on-press-escape="true"
      :close-on-click-modal="false"
      width="25%">
      <el-collapse v-model="activeName" accordion>
        <el-collapse-item :title="item.userNickName+'-'+timestampToDate(item.createTime)" :name="item.id" v-for="item in recordsRop" :key="item.id">
          <div>{{item.records}}</div>
        </el-collapse-item>
      </el-collapse>
      <div style="width: 100%; text-align: center;">
        <el-button
          plain
          class="resetButton"
          @click="isShowRecords = false">关闭</el-button>
      </div>
    </el-dialog>
    <!-- 表格 -->
    <el-table
      :data="tableData"
      :header-cell-style="{ background:'#f8f8f9',color:'#515a6e'}"
      size="mini"
      @select="selectOptions"
      @selection-change="handleSelectionChange"
      style="width: 100%; margin-top: 5px;">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        type="index"
        label="序号"
        width="50">
      </el-table-column>
      <el-table-column
        prop="name"
        label="客户名称"
        width="90">
        <template slot-scope="scope">
          <span>
            <span v-show="scope.row.isRepeat" class="repeatBtn">重复</span>{{ scope.row.name }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="phone"
        label="客户手机号"
        width="120">
      </el-table-column>
      <el-table-column
        prop="quota"
        width="90"
        :show-overflow-tooltip="true"
        label="额度">
        <template slot-scope="scope">
          <span>{{ scope.row.quota === null ? '-' : scope.row.quota }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="isFlag"
        width="100"
        align="center"
        label="标记重要客户">
          <template slot-scope="scope">
            <div style="font-size: 30px;" @click="changeFlag(scope.row.id)">
              <i class="el-icon-star-off" v-if="scope.row.isFlag === 0"></i>
              <i class="el-icon-star-on" v-else></i>
            </div>
          </template>
      </el-table-column>
      <el-table-column
        prop="seasName"
        width="90"
        :show-overflow-tooltip="true"
        label="公海名称">
      </el-table-column>
      <el-table-column
        prop="clientName"
        width="90"
        :show-overflow-tooltip="true"
        label="来源名称">
      </el-table-column>
      <el-table-column
        prop="status"
        width="100"
        label="客户状态">
          <template slot-scope="scope">
            <span>{{ getStatus(scope.row.status)}}</span>
          </template>
      </el-table-column>
      <el-table-column
        prop="followUpUser"
        width="90"
        :show-overflow-tooltip="true"
        label="跟进人名称">
      </el-table-column>
      <el-table-column label="操作" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="getFlagDetail(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            v-permissions="'customers:delete'"
            @click="deletBtn(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 用户列表弹框 -->
    <el-dialog
      title="用户列表"
      :visible.sync="isShowUserList"
      @close="isShowUserList = false"
      :close-on-press-escape="true"
      :close-on-click-modal="false"
      width="30%">
      
      <el-form ref="formInSeas" :inline="true" size="small" class="demo-form-inline">
        <el-form-item label="用户">
          <el-select v-model="checkedUserId" filterable placeholder="请选择用户">
            <el-option
              v-for="item in userListArr"
              :key="item.id"
              :label="item.nickName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button 
            type="primary"
            plain
            @click="submitUser"
            class="queryButton">确定</el-button>
          <el-button
            plain
            class="resetButton"
            @click="isShowUserList = false">关闭</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <pagination
      class="pagination_container"
      :total="paginationForOut.total"
      :page-sizes="[10, 20, 50, 100]"
      :page.sync="paginationForOut.page"
      :limit.sync="paginationForOut.pageSize"
      @pagination="getResource"
    />
  </div>
</template>

<script>
import { seasList,customersSalvage,customersShareCus,customersDownloadCus } from '@/request/seas';
import { userList } from '@/request/departmentUser';
import { customersUploadExcel,customersAdd,customersSetFlag,customersFollowUpRecord,customersUpdateQualificationsByUser } from '@/request/customerList';
import { timestampToDate } from '@/until/paramRou'
import { customersResourceList } from '@/request/resourceList';
import { thirdClientList } from '@/request/thirdClientList';
import { customersBatchDelete,customersDelete } from '@/request/myCus';
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
    data() {
    //这里存放数据
      return {
        isShowUserList: false,
        checkedUserId: '',
        recordsRop: [],
        userListArr: [],
        activeName: '',
        flagDetailObj: {
          followUpRecord : ''
        },
        flagRule: {
          followUpRecord: [
            { required: true, trigger: 'blur', message: '请输入最新跟进记录' }
          ],
          quota: [
            { required: true, trigger: 'blur', message: '请输入贷款额度' }
          ],
          name: [
            { required: true, trigger: 'blur', message: '请输入您的昵称' }
          ],
          seasId: [
            { required: true, trigger: 'change', message: '请选择公海' }
          ],
          status: [
            { required: true, trigger: 'change', message: '请选择客户状态' }
          ],
          phone: [
            { required: true, trigger: 'blur', message: '请输入您的手机号' },
            {
              validator (_, value, callback) {
                const regTel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
                if (!regTel.test(value)) {
                  callback(new Error('手机号不符合规则'))
                } else {
                  callback()
                }
              },
              trigger: 'blur'
            }
          ]
        },
        flagStatusArr: [
          {
            name: '待跟进',
            id: 0
          },
          {
            name: '己成交',
            id: 1
          },
          {
            name: '在考虑',
            id: 2
          },
          {
            name: '己邀约待上门',
            id: 3
          },
          {
            name: '己沟通不需要',
            id: 4
          },
          {
            name: '己上门待签约',
            id: 5
          },
          {
            name: '己上门资质不服',
            id: 6
          },
          {
            name: '签约',
            id: 7
          },
          {
            name: '进件',
            id: 8
          },
          {
            name: '成交',
            id: 9
          },
        ],
        isShowRecords: false,
        showFlagDetailDia: false,
        myCusFromAdd: {
          addType: 1,
          cusName: '',
          level: '',
          phone: '',
          quota: '',
          remarks: '',
          seasId: '',
          status: ''
        },
        addMyCusRule: {
          cusName: [
            { required: true, trigger: 'blur', message: '请输入您的名字' }
          ],
          quota: [
            { required: true, trigger: 'blur', message: '请输入借款额度' }
          ],
          seasId: [
            { required: true, trigger: 'change', message: '请选择公海' }
          ],
          level: [
            { required: true, trigger: 'change', message: '请选择客户星级' }
          ],
          status: [
            { required: true, trigger: 'change', message: '请选择客户状态' }
          ],
          phone: [
            { required: true, trigger: 'blur', message: '请输入您的手机号' },
            {
              validator (_, value, callback) {
                const regTel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
                if (!regTel.test(value)) {
                  callback(new Error('手机号不符合规则'))
                } else {
                  callback()
                }
              },
              trigger: 'blur'
            }
          ]
        },
        isShowaddMyCus: false,
        permissionRole: [
          {
            name: '仅自己',
            id: 0
          },
          {
            name: '当前部门',
            id: 1
          },
          {
            name: '全公司',
            id: 2
          }
        ],
        paginationForOut: {
          page: 1,
          pageSize: 10,
          total: 20
        },
        flagCusMolde: {
          kw: '',
          clientId: '',
          value_flag: []
        },
        seasArr: [],
        tableData: [],
        mesFromArr: [],
        salvageArr: []

      };
    },
  //监听属性 类似于data概念
  computed: {
  },
  //监控data中的数据变化
  watch: {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.getResource()
    this.getSeasListArr()
    this.getMesFromList()
    this.getUserList()
  },
  //方法集合
  methods: {
    // 获取用户列表
    getUserList(){
      const userObj = {
        limit: 99999,
        page: 1
      }
      userList(userObj).then(res => {
        if (res.code === '200') {
          for (const element of res.data.records) {
            element.checked = false
          }
          this.userListArr = res.data.records || []
        }
      }).catch(err => {
        this.$message({
          message: '服务器忙~',
          type: 'warning'
        })
      })
    },
    // 确定用户
    submitUser(){
      // console.log(this.checkedUserId);
      let arr = []
      for (const element of this.salvageArr) {
        arr.push(element.id)
      }
      let shareCus = {}
      shareCus.cusIdList = arr;
      shareCus.userId = this.checkedUserId;
      // console.log(shareCus);
      
      customersShareCus(shareCus).then(res => {
        if (res.code === '200') {
          this.getResource()
          this.isShowUserList = false
          this.$message({
            type: 'success',
            message: '分配成功'
          })
        } else {
          this.isShowUserList = false
          this.$message({
            type: 'error',
            message: res.message
          })
        }
      }).catch(err => {
        this.$message({
          message: '服务器忙~',
          type: 'warning'
        })
      })
    },
    // 捞取
    salvageFun(){
      if (this.salvageArr.length <= 0) {
        this.$message({
          type: 'error',
          message: '请至少选择一位用户'
        })
      } else {
        let arr = []
        for (const element of this.salvageArr) {
          arr.push(element.id)
        }
        let shareCus = {}
        shareCus.cusIdList = arr;
        customersSalvage(shareCus).then(res => {
          if (res.code === '200') {
            this.getResource()
            this.$message({
              type: 'success',
              message: res.data
            })
          } else {
            this.$message({
              type: 'error',
              message: res.message
            })
          }
        }).catch(err => {
          this.$message({
            message: '服务器忙~',
            type: 'warning'
          })
        })
      }
    },
    // 分配
    shareFun(){
      if (this.salvageArr.length <= 0) {
        this.$message({
          type: 'error',
          message: '请先勾选客户'
        })
      } else {
        this.isShowUserList = true
      }
    },
    // 删除我的客户
    deletBtn(val){
      this.$confirm(`是否确认删除’${val.name}‘`, '提示', {
        type: 'warning',
        confirmButtonText: '确定',
        showCancelButton: '取消',
        distinguishCancelAndClose: false
      }).then(() => {
        let arr = []
        arr.push(val.id)
        let deleteCus = {}
        deleteCus.cusIdList = arr
        customersDelete(deleteCus).then(res => {
          if(res.code === '200') {
            this.getResource()
            this.$message({
              type: 'success',
              message: '操作成功'
            })
          } else {
            this.$message({
              type: 'error',
              message: res.message
            })
            return
          }
        }).catch(err => {
          this.$message({
            message: '服务器忙~',
            type: 'warning'
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消!'
        })
      })
    },
    // 批量删除客户
    deleteBtnAll(){
      if (this.salvageArr.length === 0) {
        this.$message({
          type: 'error',
          message: '请至少选择一位用户'
        })
      } else {
        this.$confirm(`是否确认删除`, '提示', {
          type: 'warning',
          cancelButtonText: '取消',
          showCancelButton: true,
          confirmButtonText: '确定',
          distinguishCancelAndClose: false
        }).then(() => {
          let arr = []
          for (const element of this.salvageArr) {
            arr.push(element.id)
          }
          let deleteCus = {}
          deleteCus.cusIdList = arr
          customersBatchDelete(deleteCus).then(res => {
            if(res.code === '200') {
              this.getResource()
              this.$message({
                type: 'success',
                message: '操作成功'
              })
            } else {
              this.$message({
                type: 'error',
                message: res.message
              })
              return
            }
          }).catch(err => {
            this.$message({
              message: '服务器忙~',
              type: 'warning'
            })
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消!'
          })
        })
      }
    },
    // 获取数据来源列表
    getMesFromList(){
      let obj = {
        limit: 99999,
        page: 1
      }
      thirdClientList(obj).then(res => {
        if (res.code === '200') {
          this.mesFromArr = res.data.records
        } else {
          this.mesFromArr = []
          this.$message({
            type: 'error',
            message: res.message
          })
        }
      }).catch(err => {
        this.$message({
          message: '服务器忙~',
          type: 'warning'
        })
      })
    },
    // 下载客户
    downLoadCus(){
      if (this.salvageArr.length === 0) {
        this.$message({
          type: 'error',
          message: '请至少选择一位用户'
        })
      } else {
        let arr = []
        for (const element of this.salvageArr) {
          arr.push(element.id)
        }
        let downloadCus = {}
        downloadCus.cusIdList = arr
        customersDownloadCus(downloadCus).then(res => {
          const link = document.createElement('a');
          let blob = new Blob([res], { type: 'application/vnd.ms-excel' });
          link.download = '客户信息';
          link.style.display = 'none';
          link.href = URL.createObjectURL(blob);
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
          this.$message({
            type: 'success',
            message: '下载成功'
          })
        }).catch(err => {
          this.$message({
            message: '服务器忙~',
            type: 'warning'
          })
        })
      }
    },
    // 全选按钮
    handleSelectionChange(val){
      // console.log(val);
      this.salvageArr = val
    },
    // 单选按钮
    selectOptions(val){
      // console.log(val);
      this.salvageArr = val
    },
    // 上传文件
    uploadExcel(item){
      let params = new FormData();
      params.append("file", item.file);
      customersUploadExcel(params).then(res => {
        if (res.code === '200') {
          this.getResource()
          this.$message({
            type: "success",
            message: "上传成功",
          });
        } else {
          this.$message({
            type: 'error',
            message: res.message
          })
        }
      }).catch(err => {
        this.$message({
          message: '服务器忙~',
          type: 'warning'
        })
      })
    },
    // 上传文件失败
    fileUploadError() {
      this.$message({
        type: "error",
        message: "文件上传出现未知错误",
        showClose: true,
      });
    },
    fileUploadSuccess(response, file, fileList) {
      if (response.code === "200") {
        this.$message({
          type: "success",
          message: "上传成功",
          showClose: true,
        });
      } else {
        const msg = response.errorMessage || "文件上传失败";
        this.$message({ type: "error", message: msg, showClose: true });
      }
    },
    // 改变我的客户flag
    changeFlag(val){
      customersSetFlag({cusId :val}).then(res => {
        if (res.code === '200') {
          this.$message({
            type: 'success',
            message: '标记成功'
          })
          this.getResource()
        } else {
          this.$message({
            type: 'error',
            message: res.message
          })
        }
      }).catch(err => {
        this.$message({
          message: '服务器忙~',
          type: 'warning'
        })
      })
    },
    // 获取公海列表
    getSeasListArr(){
      seasList().then(res => {
        if (res.code === '200') {
          this.seasArr = res.data
        } else {
          this.$message({
            type: 'error',
            message: res.message
          })
        }
      }).catch(err => {
        this.$message({
          message: '服务器忙~',
          type: 'warning'
        })
      })
    },
    // 获取资源中心
    getResource(){
      let flagListObj = {}
      if (this.flagCusMolde.value_flag === null) {
        flagListObj = {
          kw: this.flagCusMolde.kw,
          limit: this.paginationForOut.pageSize,
          page: this.paginationForOut.page,
          clientId: this.flagCusMolde.clientId,
          seasId: '',
          startTime: '',
          endTime: ''
        }
      } else {
        flagListObj = {
          kw: this.flagCusMolde.kw,
          limit: this.paginationForOut.pageSize,
          page: this.paginationForOut.page,
          clientId: this.flagCusMolde.clientId,
          seasId: '',
          startTime: timestampToDate(this.flagCusMolde.value_flag[0]) === 'NaN-aN-aN' ? '' : timestampToDate(this.flagCusMolde.value_flag[0]),
          endTime: timestampToDate(this.flagCusMolde.value_flag[1]) === 'NaN-aN-aN' ? '' : timestampToDate(this.flagCusMolde.value_flag[1])
        }
      }
      
      customersResourceList(flagListObj).then(res => {
        if(res.code === '200') {
          this.tableData = res.data.records
          if (res.data.total > 0 && Math.ceil(res.data.total / this.paginationForOut.size) < this.paginationForOut.page) {
            this.paginationForOut.page = Math.ceil(res.data.total / this.paginationForOut.size)
            this.getResource()
          } else {
            this.paginationForOut.total = res.data.total
          }
        } else {
          this.tableData = []
          this.$message({
            message: res.message,
            type: 'warning'
          })
        }
      }).catch(err => {
        this.$message({
          message: '服务器忙~',
          type: 'warning'
        })
      })
    },
    // 打开弹框新增我的客户
    addmyCusBtn(){
      this.isShowaddMyCus = true
    },
    // 关闭新增我的客户弹框
    addPopClose(name){
      // this.resetForm(name)
      this.$refs[name].resetFields();
      this.isShowaddMyCus = false
    },
    // 提交新我的客户
    submitMycus(){
      this.$refs.roleForm.validate((valid) => {
        if (valid) {
          customersAdd(this.myCusFromAdd).then(res => {
            if (res.code === '200') {
              this.$message({
                type: 'success',
                message: '操作成功!'
              })
              this.addPopClose()
              this.getResource()
            } else {
              this.$message({
                type: 'error',
                message: res.message
              })
            }
          }).catch(err => {
            this.$message({
              message: '服务器忙~',
              type: 'warning'
            })
          })
        }
      })
    },
    // 关闭新增弹框
    closeDia(){
      this.getResource()
      this.showFlagDetailDia = false
      this.flagDetailObj.followUpRecord = ''
    },
    // 我的客户详情
    getFlagDetail (val) {
      this.showFlagDetailDia = true
      this.flagDetailObj = val
    },
    // 查看详情跟进记录
    viewRecords(val){
      customersFollowUpRecord({cusId :val}).then(res => {
        if (res.code === '200') {
          this.isShowRecords = true
          this.recordsRop = res.data
        } else {
          this.$message({
            type: 'error',
            message: res.message
          })
        }
      }).catch(err => {
        this.$message({
          message: '服务器忙~',
          type: 'warning'
        })
      })
    },
    // 保存修改详情按钮
    addConfigUserRole () {
      const objUpdate = {
        addType: 1,
        cusId: this.flagDetailObj.id,
        cusName: this.flagDetailObj.name,
        followUpRecord: this.flagDetailObj.followUpRecord,
        level: this.flagDetailObj.level,
        phone: this.flagDetailObj.phone,
        quota: this.flagDetailObj.quota,
        remarks: this.flagDetailObj.remarks,
        seasId: this.flagDetailObj.seasId,
        status: this.flagDetailObj.status
      }
      // console.log(objUpdate);
      
      customersUpdateQualificationsByUser(objUpdate).then(res => {
        this.showFlagDetailDia = false
        this.getResource()
        if (res.code === '200') {
          this.$message({
            type: 'success',
            message: '操作成功'
          })
        } else {
          this.$message({
            type: 'error',
            message: res.message
          })
        }
      }).catch(err => {
        this.$message({
          message: '服务器忙~',
          type: 'warning'
        })
      })
    },
    // 重置 - 搜索 - 新增
    resetQuery(fromName) {
      // this.resetForm(fromName)
      this.$refs[fromName].resetFields();
      this.flagCusMolde.value_flag = []
      this.flagCusMolde.seasId = ''
      this.getResource()
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {

  },
}
</script>
<style lang='scss' scoped>
  //@import url(); 引入公共css类
  
.buttons {
  width: 100%;
  text-align: center;
  
}
.upload-demo {
  margin-left: 5px;
  display: inline;
}
</style>
